package com.beemans.common.utils

import android.annotation.SuppressLint
import android.location.LocationManager
import com.blankj.utilcode.util.PhoneUtils
import com.hjq.permissions.Permission
import com.tiamosu.fly.utils.locationManager
import java.util.*

/**
 * @author tiamosu
 * @date 2021/3/12
 */
object TelephoneUtils {

    /**
     * 手机是否开启位置服务，如果没有开启那么所有app将不能使用定位功能
     */
    fun isGPSEnabled(): Boolean {
        return locationManager?.isProviderEnabled(LocationManager.GPS_PROVIDER) ?: false
    }

    @SuppressLint("MissingPermission")
    fun getIMEI(): String {
        return when {
            PermissionHelper.isGranted(Permission.READ_PHONE_STATE) -> PhoneUtils.getIMEI() ?: ""
            else -> ""
        }
    }

    /**
     * 是否为鸿蒙系统
     */
    val isHarmonyOs: Boolean
        get() {
            return try {
                val buildExClass = Class.forName("com.huawei.system.BuildEx")
                val osBrand = buildExClass?.getMethod("getOsBrand")?.invoke(buildExClass) ?: ""
                "harmony" == osBrand.toString().lowercase(Locale.getDefault())
            } catch (x: Throwable) {
                false
            }
        }
}